package com.nsl.my_youlai.bbu2.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nsl.my_youlai.bbu2.model.entity.ApparatusRoomEntity;
import com.nsl.my_youlai.bbu2.model.query.ApparatusRoomPageQuery;
import com.nsl.my_youlai.bbu2.service.ApparatusRoomService;
import com.nsl.my_youlai.common.result.PageResult;
import com.nsl.my_youlai.common.result.Result;
import com.nsl.my_youlai.common.result.UploadFileStatus;
import com.nsl.my_youlai.mystar.enums.NslEnumTransformException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.lang.reflect.InvocationTargetException;

@RestController
@RequestMapping("/api/v1/apparatus_room")
@RequiredArgsConstructor
@Slf4j
public class ApparatusRoomController {

    private final ApparatusRoomService apparatusRoomService;

    @PostMapping("/page")
    public PageResult<ApparatusRoomEntity> getRequirementPoolPage(
            @RequestBody ApparatusRoomPageQuery queryParams
    ) {
        Page<ApparatusRoomEntity> result = apparatusRoomService.getPage(queryParams);
        return PageResult.success(result);
    }

    /**
     * 导入 需求库文件
     * @param file
     * @return
     */
    @PostMapping("/import")
    public Result<UploadFileStatus> importRequirementPoolExcel(MultipartFile file) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException, NslEnumTransformException {
        log.info("file = {}",file);
        log.info("file.getOriginalFilename() = {}",file.getOriginalFilename());

        UploadFileStatus uploadFileStatus =apparatusRoomService.importApparatusRoomlExcel(file);

        return Result.success(uploadFileStatus);
    }

}
